home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / EXPDEV.DEM < prev    next >
Text File  |  1991-04-29  |  1KB  |  47 lines

  1. PROGRAM d7r5 (input,output);
  2. (* driver for routine EXPDEV *)
  3. CONST
  4.    npts=1000;
  5.    ee=2.718281828;
  6. VAR
  7.    i,idum,j : integer;
  8.    expect,total,y : real;
  9.    trig,x : ARRAY [0..20] OF real;
  10.    glinext,glinextp : integer;
  11.    glma : ARRAY [1..55] OF real;
  12.  
  13. (*$I MODFILE.PAS *)
  14. (*$I RAN3.PAS *)
  15.  
  16. (*$I EXPDEV.PAS *)
  17.  
  18. BEGIN
  19.    FOR i := 0 to 20 DO BEGIN
  20.       trig[i] := i/20.0;
  21.       x[i] := 0.0
  22.    END;
  23.    idum := -1;
  24.    FOR i := 1 to npts DO BEGIN
  25.       y := expdev(idum);
  26.       FOR j := 1 to 20 DO BEGIN
  27.          IF ((y < trig[j]) AND (y > trig[j-1]))  THEN BEGIN
  28.             x[j] := x[j]+1.0
  29.          END
  30.       END
  31.    END;
  32.    total := 0.0;
  33.    FOR i := 1 to 20 DO BEGIN
  34.       total := total+x[i]
  35.    END;
  36.    writeln;
  37.    writeln ('exponential distribution with',npts:7,' points');
  38.    writeln ('   interval','     observed','    expected');
  39.    writeln;
  40.    FOR i := 1 to 20 DO BEGIN
  41.       x[i] := x[i]/total;
  42.       expect := exp(-(trig[i-1]+trig[i])/2.0);
  43.       expect := expect*0.05*ee/(ee-1);
  44.       writeln (trig[i-1]:6:2,trig[i]:6:2,x[i]:12:6,expect:12:6)
  45.    END
  46. END.
  47.